package com.xm.web.entity.po;

import java.util.Collection;
import java.util.Date;
import java.io.Serializable;
import java.util.List;

import lombok.*;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableField;

/**
 * <p>
 * 用户表
 * </p>
 *
 * @author yousj
 * @since 2021-08-18
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class TbUser implements Serializable, UserDetails {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 昵称
     */
    @TableField("nickname")
    private String nickname;

    /**
     * 账号
     */
    @TableField("username")
    private String username;

    /**
     * 密码
     */
    @TableField("password")
    private String password;

    /**
     * 邮箱
     */
    @TableField("email")
    private String email;

    /**
     * 头像
     */
    @TableField("portrait")
    private String portrait;

    /**
     * 地址
     */
    @TableField("address")
    private String address;

    /**
     * 个性签名
     */
    @TableField("signature")
    private String signature;

    /**
     * 过期时间
     */
    @TableField("expire")
    private Date expire;

    /**
     * 状态, 0 停用, 1启用
     */
    @TableField("status")
    private Integer status;

    /**
     * 创建时间
     */
    @TableField("create_time")
    private Date createTime;

    /**
     * 更新时间
     */
    @TableField("update_time")
    private Date updateTime;

    @TableField(exist = false)
    private Object menus;
    @TableField(exist = false)
    private String token;
    @TableField(exist = false)
    private List<GrantedAuthority> authorities;

    public TbUser(Integer id, String nickname, String username, String password, String email, String portrait,
                  String address, String signature, Date expire, Integer status, Date createTime, Date updateTime) {
        this.id = id;
        this.nickname = nickname;
        this.username = username;
        this.password = password;
        this.email = email;
        this.portrait = portrait;
        this.address = address;
        this.signature = signature;
        this.expire = expire;
        this.status = status;
        this.createTime = createTime;
        this.updateTime = updateTime;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
